package com.ccb;



import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.NetPermission;
import java.nio.CharBuffer;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.zip.GZIPInputStream;



import net.sf.cindy.Buffer;
import net.sf.cindy.buffer.BufferBuilder;

import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

import com.ccb.afm.util.CodingFactory;

import cn.tworen.demou.amf.Amf3Decode;
import cn.tworen.demou.remoting.AmfMessage;
import cn.tworen.demou.remoting.amf.AmfDecode;





public class BaiDuUtils {
	 public String username = "litertiger";
	 public String password = "XXXXXXXXX";
	
	 public boolean login()
	 {
		return true; 
	 }
	 
	 public void getPrice()
	 {
		 HttpClient client = new HttpClient();
		 HostConfiguration cf   =     new   HostConfiguration();
		 cf.setHost("baiduhouse.17c.cn");
		/* cf.setProxy(  "127.0.0.1"  ,   8888  );*/
		 client.setHostConfiguration(cf);
		 
		 PostMethod method = new PostMethod();
		
		 method.setPath("/apf_houseking/baidu_stable/index.php?c=api&a=gateway");
		 //add cookie
		/* method.setRequestHeader("Cookie", "86c908a6198b130f7b05474c4af8e75f=78742d5eaf5bb62725736a8614ff6463; 86c908a6198b130f7b05474c4af8e75f_time=1284266142391; 86c908a6198b130f7b05474c4af8e75f_session_key=3bjF%2Fib%2BFcqjx2jidUo9FTNun%2BsJeXt9X7ubmJ8a4%2BB0i2r0SzAiprVK1dCpxhVmXMirnHjhCNCRRkWrNcQOe%2FMid5hdgUmmDikdRGbCiSS5B4CqplKwkg7oGP4992IH5kpNU%2B8hAva1xTbbI4v2GQbgFA2uXoNP3bidaASKKX4t0%2FgrLiWRSfkM%2BHwX1KpDTlC5YU4fMaaxeurTSt1NJfNMz4PmL88cuMMYi05hEBKOHoV%2F8W7Ex%2FCJEEnuDitS; 86c908a6198b130f7b05474c4af8e75f_portrait=7d976c6974657274696765725200; 86c908a6198b130f7b05474c4af8e75f_user=2533634957; houseking=eea4a0a52d0c33e5f28654abafb1a36e");
		 method.setRequestHeader("Accept-Language","zh-CN");
		 method.setRequestHeader("Referer","http://swf4.17c.cn/hkswf/swf_20100802/Main001.swf");
		 method.setRequestHeader("x-flash-version","10,1,82,76");
		 method.setRequestHeader("Content-Type","application/x-amf");
		 method.setRequestHeader("Accept-Encoding","gzip, deflate");
		 method.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; baiduds; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
		 method.setRequestHeader("Host","baiduhouse.17c.cn");
		 method.setRequestHeader("Connection","Keep-Alive");
		 method.setRequestHeader("Pragma","no-cache");*/
		 
		 //method.setRequestHeader("Host","baiduhouse.17c.cn");
		 //method.setRequestHeader("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
		 //method.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
		 //method.setRequestHeader("Accept-Language","en-us,zh-cn;q=0.7,zh;q=0.3");
		 method.setRequestHeader("Accept-Encoding","gzip,deflate");
		 //method.setRequestHeader("Accept-Charset","GB2312,utf-8;q=0.7,*;q=0.7");
		 //method.setRequestHeader("Keep-Alive","115");
		 //method.setRequestHeader("Connection","keep-alive");
		 //method.setRequestHeader("Cookie","86c908a6198b130f7b05474c4af8e75f=78742d5eaf5bb62725736a8614ff6463; 86c908a6198b130f7b05474c4af8e75f_time=1284266142391; 86c908a6198b130f7b05474c4af8e75f_session_key=3bjF%2Fib%2BFcqjx2jidUo9FTNun%2BsJeXt9X7ubmJ8a4%2BB0i2r0SzAiprVK1dCpxhVmXMirnHjhCNCRRkWrNcQOe%2FMid5hdgUmmDikdRGbCiSS5B4CqplKwkg7oGP4992IH5kpNU%2B8hAva1xTbbI4v2GQbgFA2uXoNP3bidaASKKX4t0%2FgrLiWRSfkM%2BHwX1KpDTlC5YU4fMaaxeurTSt1NJfNMz4PmL88cuMMYi05hEBKOHoV%2F8W7Ex%2FCJEEnuDitS; 86c908a6198b130f7b05474c4af8e75f_portrait=7d976c6974657274696765725200; 86c908a6198b130f7b05474c4af8e75f_user=2533634957; houseking=eef909014a6604b69f99339195b5b2c3");
		 //method.setRequestHeader("Referer","http://swf4.17c.cn/hkswf/swf_20100802/Main001.swf");
		 //method.setRequestHeader("Content-type","application/x-amf");
		 //method.setRequestHeader("Content-length","100");
		 
		 try {
			method.setRequestBody(new FileInputStream("c:/input.log"));

		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		 
         
		 
		 //add 
		 try {
			 
			 int status=client.executeMethod(method);
			
			AmfMessage message= CodingFactory.decodezipmsg(method.getResponseBodyAsStream()); 
			
			System.out.println(message.getBodies().get(0).getValue());
		      
		      //Amf3Decode ad=new Amf3Decode();
		     

			
			 
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		 
	 }
	 public static void main(String []args)
	 {
		 
		 BaiDuUtils bDuUtils=new BaiDuUtils();
		 bDuUtils.getPrice();
	 }
	 
	 
	 
}
